<?php
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

//'response.write "CmbModulo =" & Request("CmbModulo") & "<br>"
//'response.write "CmbCategoria =" & Request("CmbCategoria") & "<br>"
//'response.write "CmbSubCategoria =" & Request("CmbSubCategoria") & "<br>"
//'response.write "Hidid1 =" & Request("Hidid1") & "<br>"
//'response.write "opc =" & Request("opc") & "<br>"


//  '*****************************
//  'N I V E L    1
//  '***************************** 

$strSql="select * from solotb_nivel1 order by des";
SoloFun_ExecSql ($strSql,$arrData1);

if ($_REQUEST["CmbModulo"]!="") {
    $strid1=$_REQUEST["CmbModulo"];
}else {
    $strid1=$arrData1[0][0];
}	  


//'   response.write strid1
//'   response.write strsql & "<br>"

//  '*****************************
//  'N I V E L    2
//  '***************************** 
//'   If Request("CmbModulo")<>"" then   
//'      strSql=strSql & " where id1=" & Request("CmbModulo")
//'   else
//'      strSql=strSql & " where id1=" & arrData1(0,0) 
//'   end if	  

$strSql ="select * from solotb_nivel2";
$strSql .= " where id1=" . $strid1;
$strSql .= " order by des";
SoloFun_ExecSql ($strSql,$arrData2);
// '  response.write strsql & "<br>"


//  '*****************************
//  'N I V E L    3
//  '***************************** 
switch ($_REQUEST["opc"]) {
    case 1:
//              'Empresa
        $strid2=$arrData2[0][1];
        break;
    case 2:
    case 3:
//          'Categoria 
        $strid2=$_REQUEST["CmbCategoria"];
        break;
    default:
        $strid2=$arrData2[0][1];
        break;
}

$strSql="select * from solotb_nivel3 ";
$strSql .= " where id2=" . $strid2;    	  
$strSql .= " order by des";


//'   response.write strSql& "<br>"

SoloFun_ExecSql ($strSql,$arrData3);

// '*****************************
//  'N I V E L    4
//  '***************************** 
switch ($_REQUEST["opc"]) {
    case 1:
    case 2:
//              'Empresa
        $strid3=$arrData3[0][1];
        break;
    case 3:
//              'SubCategoria 
        $strid3=$_REQUEST["CmbSubCategoria"];
        break;
    default:
        $strid3=$arrData3[0][1];
        break;
}
if ($_REQUEST["opc"]=="G") {
    $strid3=$_REQUEST["CmbSubCategoria"];
    $ds3=$_REQUEST["ds3"];
}	   

$strSql="select * from solotb_nivel4 ";
$strSql .= " where id3=" . $strid3;    	  
$strSql .= " order by des";

//'   response.write strSql& "<br>"
SoloFun_ExecSql ($strSql,$arrData4);
//  ' rw"",arrData4(0,0)
//  ' re


//  '*****************************
//  'N I V E L    5
//  '***************************** 
switch ($_REQUEST["opc"]) {
    case 1:
//              'Empresa
        $strid4=$arrData4[0][1];
        break;
    case 2:
    case 3:
//              'SubCategoria
        $strid4=$_REQUEST["CmbSubCategoria2"];
//	   '  rw"aqui",Request("CmbSubCategoria2")
//'		   re
        break;
    default:
        $strid4=$arrData4[0][1];
        break;
}
$strSql="select * from solotb_nivel5 ";
$strSql .= " where id4=" . $strid4;
$strSql .= " order by des";

//'   response.write strSql& "<br>"
SoloFun_ExecSql ($strSql,$arrData5);
//'rw"",strSql
//'re

// '*****************************
//  'Elegir el maximo del 5 nivel
//  '*****************************
$strSql="select (max(id5)+1) as id  from solotb_nivel5";
//'   If request("CmbSubcategoria")<>"" then
//'	     strSql=strSql & " having id3=" & Request("CmbSubcategoria")
//'   else
//'	     strSql=strSql & " having id3=" & arrData4(0,0)
//'   end if
$strSql .= " where id4=" . $strid4;
$oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
        $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
if (!$oConexion->EjecutarQuery($strSql)) {
    $strERROR=1;
    $err=0;
}
//   $MaxId=ObjCons.fields(0)
$MaxId = $oConexion->getData("NUM");
$MaxId = $MaxId[0][0];
if (is_null($MaxId) || $MaxId=="1") {
    $MaxId=($strid4*100)+1;
}
$oConexion->Cerrar();

//'   response.write strSql& "<br>"

//'response.write "id1=" & strid1 & "<br>"
//'response.write "id2=" &  strid2 & "<br>"
//'response.write "id3=" &  strid3 & "<br>"
//'response.write "id4=" &  MaxID & "<br>"

?>
<html>
    <head>
        <title>Documentacion</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
        <SCRIPT type="text/JavaScript" src="Includes/Solofun_generales.js"></SCRIPT></head>

    <body topmargin=0 leftmargin=0>
        <!-- Include File="includes/trn_header.asp" -->
        <p align="center" class="SoloStyle_TituloPaginas">Tabla de Categor&iacute;as 3</p>
        <form name="frmIngreso" action="trn_GrabaSubCategoria3.php" method="POST">
            <table border="0" width="50%" align="center">
                <tr>
                    <td width="30%" class="SoloStyle_Etiqueta"><strong>Grupo de servicio </strong></td>
                    <td width="70%">
                        <?php
//  '*****************************
//  'N I V E L    1
//  '*****************************
                        ?>
                        <select name="CmbModulo" id="CmbModulo" class="SoloStyle_Texto" onChange="submitpage('trn_SubCategorias3.php','1');" style="width:185">
                            <?php
                            for ($i=0;$i < count($arrData1);$i++) {
                                $ind=$arrData1[$i][0];
                                $jnd=$_REQUEST["CmbModulo"];
                                if ($jnd==$ind) {
                                    echo "<option value='" . $arrData1[$i][0] . "' SELECTED >" . $arrData1[$i][1] . "</option>";

                                } else {
                                    echo "<option value='" . $arrData1[$i][0] . "'>" . $arrData1[$i][1] . "</option>";
                                }
                            }
                            ?>
                        </select> </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Departamento</b></td>
                    <td>
                        <?php
//  '*****************************
//  'N I V E L    2
//  '*****************************
                        ?>
                        <select name="CmbCategoria" id="select" class="SoloStyle_Texto" onChange="submitpage('trn_SubCategorias3.php','2');" style="width:185">
                            <?php
                            if (!$bEOF2) {
                                for ($i=0 ;$i < count($arrData2);$i++) {
                                    $ind2=$arrData2[$i][1];
                                    $jnd2=$_REQUEST["CmbCategoria"];
                                    if ($jnd2==$ind2) {
                                        echo "<option value='" . $arrData2[$i][1] . "' SELECTED >" . $arrData2[$i][2] . "</option>";
                                    }else {
                                        echo "<option value='" . $arrData2[$i][1] . "'>" . $arrData2[$i][2] . "</option>";
                                    }
                                }
                            }else {
                                echo "<option value='0'>" . "NO HAY DATOS" . "</option>";
                            }
                            ?>
                        </select></td>
                </tr>
                <!-- NIVEL DE SUCATEGORIAS 2-->
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Categor&iacute;a</b></td>
                    <td>
                        <?php
//  '*****************************
//  'N I V E L    3
//  '*****************************
                        ?>
                        <select name="CmbSubCategoria" id="select3" class="SoloStyle_Texto" onChange="submitpage('trn_SubCategorias3.php','3');"style="width:185">
                            <?php
                            if (!$bEOF3) {
                                for ($i=0;$i < count($arrData3);$i++) {
                                    $ind2=$arrData3[$i][1];
                                    $jnd2=$_REQUEST["CmbSubCategoria"];
                                    If ($jnd2==$ind2) {
                                        echo "<option value='" . $arrData3[$i][1] . "' SELECTED >" . $arrData3[$i][2] . "</option>";
                                    }else {
                                        echo "<option value='" . $arrData3[$i][1] . "'>" . $arrData3[$i][2] . "</option>";
                                    }
                                }
                            }else {
                                echo "<option value='0'>" . "NO HAY DATOS" . "</option>";
                            }
                            ?>
                        </select></td>
                </tr>
                <!-- -->

                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Categor&iacute;a 2</b></td>
                    <td>
                        <?php
//  '*****************************
//  'N I V E L    4
//  '*****************************
                        ?>
                        <select name="CmbSubCategoria2" class="SoloStyle_Texto" onChange="submitpage('trn_SubCategorias3.php','3');"style="width:185">
                            <?php
                            if (!$bEOF4) {
                                for ($i=0;$i < count($arrData4);$i++) {
                                    $ind2=$arrData4[$i][1];
                                    $jnd2=$_REQUEST["CmbSubCategoria2"];
                                    if (jnd2==ind2) {
                                        echo "<option value='" . $arrData4[$i][1] . "' SELECTED >" . $arrData4[$i][2] . "</option>";
                                    }else {
                                        echo "<option value='" . $arrData4[$i][1] . "'>" . $arrData4[$i][2] . "</option>";
                                    }
                                }
                            }else {
                                echo "<option value='0'>" . "NO HAY DATOS" . "</option>";
                            }
                            ?>
                        </select></td>
                </tr>
                <!-- -->
                <tr>
                    <td class="SoloStyle_Etiqueta">C&oacute;digo</td>
                    <td><input name="hidId1" type="text" class="SoloStyle_Texto" value="<?php echo $MaxId;?>" size="40" readonly></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Nueva Categor&iacute;a 3</td>
                    <td><input name="ATxtDesc" type="text" class="SoloStyle_Texto" id="ATxtDesc" size="40" maxlenght="50"></td>
                </tr>
            </table>
            <br><center>
                <input type="button" name="CmdGrabar" value="Grabar" class="SoloStyle_Boton" onClick="SoloFun_Submit(document.frmIngreso)"></center>
            <input type="hidden" name="opc" value="G">
        </form>
        <table width="75%" border="0" align="center" class="SoloStyle_Grid">
            <tr class="SoloStyle_Etiqueta">
                <td width="60%"> Categor&iacute;as 3</td>
                <td width="40%">Acci&oacute;n</td>
            </tr>
            <?php for ($i=0;$i < count($arrData5);$i++) {?>
            <tr>
                <td><?php echo $arrData5[$i][2];?></td>
                <td><a href="trn_GrabaSubCategoria3.php?id1=<?php echo $strid1;?>&id2=<?php echo $strid2;?>&id3=<?php echo $strid3;?>&id4=<?php echo $strid4;?>&id5=<?php echo $arrData5[$i][1];?>&ds5=<?php echo $arrData5[$i][2];?>&opc=M">
                        <img src='iconos/soloico_modificar.gif' alt='Modificar' width="23" height="19" border='0' style='cursor:hand' ></a>&nbsp;
                    <a href="#" onClick="Comprobar('trn_GrabaSubCategoria3.php?id1=<?php echo $strid1;?>&id2=<?php echo $strid2;?>&id3=<?php echo $strid3;?>&id4=<?php echo $strid4;?>&id5=<?php echo $arrData5[$i][1];?>&ds5=<?php echo $arrData5[$i][2];?>&opc=E')">
                        <img src='iconos/soloico_eliminar.gif' alt='Borrar Campos' width="23" height="19" border='0' style='cursor:hand'></a>&nbsp;
                </td>
            </tr>
                <?php }?>
        </table>
    </body>
</html>
<!--#include file="Includes/soloFun_ShowMessages.php"-->
<SCRIPT type="text/JavaScript" src="PHPMailer/fun_generales.js"></SCRIPT>
<!-- include file="includes/error.inc"-->
<script type="text/JavaScript">
    function Comprobar(pagina){
        var conf = confirm("Confirma Eliminar");
        if (conf)
            window.location.href = pagina;
    }

</script>